package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.domain.db.QuestionOptions;
import com.itheima.mapper.QuestionOptionsMapper;
import com.itheima.service.db.QuestionOptionsService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class QuestionOptionsServiceImpl implements QuestionOptionsService {

    @Autowired
    QuestionOptionsMapper questionOptionsMapper;

    /**
     * 根据问题id查询问题选项
     * @param questionId
     * @return
     */
    @Override
    public List<QuestionOptions> findByQuestionId(Integer questionId) {
        //1.创建查询条件
        LambdaQueryWrapper<QuestionOptions> qw =new LambdaQueryWrapper<>();
        qw.eq(QuestionOptions::getQuestionId,questionId);
        qw.orderByAsc(QuestionOptions::getSort);//根据排序系数升序排列
        //2.查询数据库
        List<QuestionOptions> questionOptions = questionOptionsMapper.selectList(qw);

        return questionOptions;
    }

    /**
     * 根据选项id查询选项信息
     * @param optionId
     * @return
     */
    @Override
    public QuestionOptions findById(String optionId) {
       return questionOptionsMapper.selectById(optionId);
    }
}
